package com.zyp.boot10.controller;

import com.zyp.boot10.entity.Class;
import com.zyp.boot10.mapper.ClassMapper;
import com.zyp.boot10.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/class/")
public class ClassController {
    @Autowired
    ClassMapper mapper;

    @RequestMapping("select")
    public List<Class> select() {
        return mapper.select();
    }

    @RequestMapping("insert")
    public void insert(@RequestBody Class c) {
        mapper.insert(c);
    }

    @Autowired
    StudentMapper studentMapper;
    @RequestMapping("/delete")
    public void delete(int id) {
        mapper.deleteById(id);
        // 同时删除该班级的所有学生
        studentMapper.deleteByCid(id);
    }

    @RequestMapping("/selectById")
    public Class selectById(int id) {
        return mapper.selectById(id);
    }
}
